package nl.infodation.emr.utility;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EncryptionUtil {
	
	private static final Logger LOG = LoggerFactory.getLogger(EncryptionUtil.class);
	/**
	 * EncryptionUtil password follow md5
	 * @param user
	 * @param pwd
	 * @return new password encrypted
	 */
	public static String encryption(final String pwd){
		String encrypted = "";
		try {
			final MessageDigest messageDigest = MessageDigest.getInstance(Constants.ENCRYPTION_PATTERN);
			messageDigest.reset();
			messageDigest.update(pwd.getBytes(), 0, pwd.length());
			encrypted = new BigInteger(1, messageDigest.digest()).toString(16);
		}catch(NoSuchAlgorithmException ex) {
			LOG.error("EncryptionUtil passord failed", ex);
		}
		return encrypted;
	}
}
